/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support.pay;

import com.yanlight.Constants;
import com.yanlight.app.service.AlipayService;
import com.yanlight.app.service.PayService;
import com.yanlight.app.service.WxpayService;
import com.yanlight.exception.ErrorType;
import com.yanlight.exception.TradeException;
import com.yanlight.support.BeanContext;
import com.yanlight.type.PayType;
import com.yanlight.util.CookieUtil;
import com.yanlight.util.LogUtil;
import com.yanlight.util.WebUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author haolw
 * @time 2017/10/25
 */
public abstract class PayFactory {

    public static String getPayView(HttpServletRequest request) {
        String view = null;
        if (WebUtil.isAlipayBrowse(request)) {
            view = Constants.ALIPAY_VIEW;
        } else if (WebUtil.isWxBrowse(request)) {
            view = Constants.WXPAY_VIEW;
        }
        return view;
    }

    public static PayService getPayService(HttpServletRequest request) {
        PayService payService = null;
        if (WebUtil.isAlipayBrowse(request)) {
            payService = BeanContext.getBean(AlipayService.class);
        } else if (WebUtil.isWxBrowse(request)) {
            payService = BeanContext.getBean(WxpayService.class);
        }
        return payService;
    }

    public static PayService getPayService(Integer payType) {
        PayService payService = null;
        if (PayType.ALIPAY.getType().equals(payType)) {
            payService = BeanContext.getBean(AlipayService.class);
        } else if (PayType.WXPAY.getType().equals(payType)) {
            payService = BeanContext.getBean(WxpayService.class);
        } else {
            throw TradeException.error(ErrorType.NO_SUPPORT_PAYMENT);
        }
        return payService;
    }

}
